# -*- coding: utf-8 -*-

"""
@Datetime: 2019/5/21
@Author: Zhang Yafei
"""
# 用来存储名片(列表)
card_infors = []


def print_menu():
    """完成打印功能菜单"""
    print("=" * 50)
    print(" 名片管理系统 v0.1")
    print(" 1.添加一个名片")
    print(" 2.删除一个名片")
    print(" 3.修改一个名片")
    print(" 4.查询一个名片")
    print(" 5.显示所有名片")
    print(" 6.退出系统")
    print("=" * 50)


def add_new_card_infor():
    """完成添加一个新的名片"""
    new_name = input("请输入新的名字:")
    new_qq = input("请输入新的qq:")
    new_weixin = input("请输入新的微信:")
    new_addr = input("请输入新的住址:")

    # 定义一个新的字典，用来存储一个新的名片
    new_infor = {}
    new_infor['name'] = new_name
    new_infor['qq'] = new_qq
    new_infor['weixin'] = new_weixin
    new_infor['addr'] = new_addr

    # 将一个字典添加到列表中
    global card_infors
    card_infors.append(new_infor)

    print(card_infors)


def del_card_infor():
    """用来查询一个名片"""
    global card_infors
    find_flag = 0
    del_name = input("删除的姓名是：")
    for temp in card_infors:
        if del_name == temp['name']:
            card_infors.remove(temp)
            find_flag = 1
            print(card_infors)
            break
    # 判断是否找到了
    if find_flag == 0:
        print("查无此人")


def show_all_infor():
    """显示所有的名片信息"""
    global card_infors

    for temp in card_infors:
        print("%s\t%s\t%s\t%s\t" % (temp['name'], temp['qq'], temp['weixin'], temp['addr']))


def chang_card_infor():
    """完成对名片信息的修改"""
    global card_infors

    find_flag = 0
    name = input("你要修改的名片的姓名是：")
    for temp in card_infors:
        if name == temp['name']:
            temp['name'] = input("姓名:")
            temp['qq'] = input("qq:")
            temp['weixin'] = input("微信:")
            temp['addr'] = input("地址:")
            print("姓名\tQQ\t微信\t住址")
            print("%s\t%s\t%s\t%s\t" % (temp['name'], temp['qq'], temp['weixin'], temp['addr']))
            find_flag = 1
            break
    if find_flag == 0:
        print("查无此人")


def find_card_infor():
    """查找名片上的信息"""
    global card_infors
    find_name = input("请输入要查找的名字：")
    find_flag = 0  # 默认表示没有找到
    for temp in card_infors:
        if find_name == temp['name']:
            print("%s\t%s\t%s\t%s\t" % (temp['name'], temp['qq'], temp['weixin'], temp['addr']))
            find_flag = 1
            break
    # else:
    # print("查无此人")
    # p判断是否找到了
    if find_flag == 0:
        print("查无此人")


def main():
    # 1. 打印功能提示
    print_menu()
    while True:
        # 2.获取用户的输入
        num = int(input("请输入操作序列："))
        # 3.根据用户的输入执行相应的功能
        if num == 1:
            add_new_card_infor()

        elif num == 2:
            del_card_infor()

        elif num == 3:
            chang_card_infor()

        elif num == 4:
            find_card_infor()

        elif num == 5:
            show_all_infor()

        elif num == 6:
            break
        else:
            print("你输入的信息有误，请重新输入！")


main()
